<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>zoom.cpp Example File (mandelbrot/zoom.cpp)</title>
  <link rel="stylesheet" type="text/css" href="style/style.css" />
  <script src="scripts/jquery.js" type="text/javascript"></script>
  <script src="scripts/functions.js" type="text/javascript"></script>
  <script src="./scripts/superfish.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="style/superfish.css" />  <script src="./scripts/narrow.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="style/narrow.css" />
  <!--[if IE]>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="no">
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="style/style_ie8.css">
<![endif]-->
</head>
<body class="" onload="CheckEmptyAndLoadList();">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="150"><img src="images/qt-logo.png" align="left" border="0" />&nbsp;&nbsp;<img src="images/qtopencl-logo.png" border="0" /></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"> <a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="qtopencl-all-classes.html"><font color="#004faf">All Classes</font></a></td>
</table><h1 class="title">zoom.cpp Example File</h1>
<span class="small-subtitle">mandelbrot/zoom.cpp</span>
<!-- $$$mandelbrot/zoom.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="highlightedCode brush: cpp"><span class="comment">    /****************************************************************************
    **
    ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    ** All rights reserved.
    ** Contact: Nokia Corporation (qt-info@nokia.com)
    **
    ** This file is part of the QtOpenCL module of the Qt Toolkit.
    **
    ** $QT_BEGIN_LICENSE:LGPL$
    ** No Commercial Usage
    ** This file contains pre-release code and may not be distributed.
    ** You may use this file in accordance with the terms and conditions
    ** contained in the Technology Preview License Agreement accompanying
    ** this package.
    **
    ** GNU Lesser General Public License Usage
    ** Alternatively, this file may be used under the terms of the GNU Lesser
    ** General Public License version 2.1 as published by the Free Software
    ** Foundation and appearing in the file LICENSE.LGPL included in the
    ** packaging of this file.  Please review the following information to
    ** ensure the GNU Lesser General Public License version 2.1 requirements
    ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    **
    ** In addition, as a special exception, Nokia gives you certain additional
    ** rights.  These rights are described in the Nokia Qt LGPL Exception
    ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    **
    ** If you have questions regarding the use of this file, please contact
    ** Nokia at qt-info@nokia.com.
    **
    **
    **
    **
    **
    **
    **
    **
    ** $QT_END_LICENSE$
    **
    ****************************************************************************/</span>

    #include &quot;zoom.h&quot;
    #include &quot;image.h&quot;

    Zoom::Zoom()
    {
    }

    Zoom::~Zoom()
    {
    }

    void Zoom::addStep(double centerx, double centery,
                       double hdiameter, int iterations)
    {
        ZoomStep step;
        step.centerx = centerx;
        step.centery = centery;
        step.hdiameter = hdiameter;
        step.iterations = iterations;
        steps.append(step);
    }

    static inline double interpolate(double x, double y, double amt)
    {
        return x + (y - x) * amt;
    }

    static inline int interpolate(int x, int y, double amt)
    {
        return qRound(x + (y - x) * amt);
    }

    void Zoom::generate(Image *image, qreal value, const Palette&amp; palette)
    {
        Q_ASSERT(steps.size() &gt;= 2);
        int posn, iterations;
        if (value &lt;= 0.0f) {
            image-&gt;setRegion(steps[0].centerx, steps[0].centery,
                             steps[0].hdiameter);
            iterations = steps[0].iterations;
        } else if (value &gt;= 1.0f) {
            posn = steps.size() - 1;
            image-&gt;setRegion(steps[posn].centerx, steps[posn].centery,
                             steps[posn].hdiameter);
            iterations = steps[posn].iterations;
        } else {
            int groups = steps.size() - 1;
            posn = int(value * groups);
            double lower = double(posn) / groups;
            double upper = double(posn + 1) / groups;
            double amt = (value - lower) / (upper - lower);
            image-&gt;setRegion
                (interpolate(steps[posn].centerx, steps[posn + 1].centerx, amt),
                 interpolate(steps[posn].centery, steps[posn + 1].centery, amt),
                 interpolate(steps[posn].hdiameter, steps[posn + 1].hdiameter, amt));
            iterations = interpolate(steps[posn].iterations,
                                     steps[posn + 1].iterations, amt);
        }
        image-&gt;generate(iterations, palette);
    }

    WikipediaZoom::WikipediaZoom()
    {
        <span class="comment">// This table defines the steps in the 14-step Mandelbrot zoom at</span>
        <span class="comment">// http://commons.wikimedia.org/wiki/Mandelbrot_set</span>
        <span class="comment">//</span>
        <span class="comment">// With float precision, step 7 is roughly at the rounding error limit.</span>
        addStep(-.7, 0, 3.0769, 200);              <span class="comment">// Starting point</span>
        addStep(-.87591, .20464, .53184, 200);     <span class="comment">// Step 1</span>
        addStep(-.759856, .125547, .051579, 500);
        addStep(-.743030, .126433, .016110, 700);
        addStep(-.7435669, .1314023, .0022878, 700);
        addStep(-.74364990, .13188204, .00073801, 2000);
        addStep(-.74364085, .13182733, .00012068, 2000);
        addStep(-.743643135, .131825963, .000014628, 2000); <span class="comment">// Step 7</span>
    #if 0
        addStep(-.7436447860, .1318252536, .0000029336, 2000);
        addStep(-.74364409961, .13182604688, .00000066208, 2000);
        addStep(-.74364386269, .13182590271, .00000013526, 2000);
        addStep(-.743643900055, .131825890901, .000000049304, 2000);
        addStep(-.7436438885706, .1318259043124, .0000000041493, 2000);
        addStep(-.74364388717342, .13182590425182, .00000000059849, 2000);
        addStep(-.743643887037151, .131825904205330, .000000000051299, 2000); <span class="comment">// Step 14</span>
    #endif
    }

    GoldenGradientZoom::GoldenGradientZoom()
    {
        <span class="comment">// Golden Gradient zoom from:</span>
        <span class="comment">// http://commons.wikimedia.org/wiki/File:Mandelbrot_sequence_new.gif</span>
        double centerx = -0.743643887037158704752191506114774;
        double centery = 0.131825904205311970493132056385139;
        double diameter = 4.0;
        addStep(centerx, centery, diameter, 200);
        addStep(centerx, centery, diameter / 2, 200);
        addStep(centerx, centery, diameter / 4, 500);
        addStep(centerx, centery, diameter / 8, 300);
        addStep(centerx, centery, diameter / 16, 300);
        addStep(centerx, centery, diameter / 32, 500);
        addStep(centerx, centery, diameter / 64, 1000);
        addStep(centerx, centery, diameter / 128, 1000);
        addStep(centerx, centery, diameter / 256, 1000);
        addStep(centerx, centery, diameter / 512, 1000);
        addStep(centerx, centery, diameter / 1024, 1000);
        addStep(centerx, centery, diameter / 2048, 2000);
        addStep(centerx, centery, diameter / 4096, 2000);
        addStep(centerx, centery, diameter / 8192, 2000);
        addStep(centerx, centery, diameter / 16384, 2000);
        addStep(centerx, centery, diameter / 32768, 2000);
        addStep(centerx, centery, diameter / 65536, 2000);
        addStep(centerx, centery, diameter / 131072, 2000);
    }</pre>
</div>
<!-- @@@mandelbrot/zoom.cpp -->
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td align="left">Copyright &copy; 2010 Nokia Corporation</td>
<td align="right">QtOpenCL Documentation</td>
</tr></table></div></address>  <script src="scripts/functions.js" type="text/javascript"></script>
  <script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-4457116-5']);
  _gaq.push(['_trackPageview']);
  (function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
  </script>
</body>
</html>
